home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / BSCRISEC.C < prev    next >
C/C++ Source or Header  |  1993-05-31  |  3KB  |  100 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    bscrisec.c
  5. //   Title:    Base library
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //
  24. //    This module contains contains code to manage critical sections under OS/2.
  25. //    This code is not useful under other OS's but the functions are still used
  26. //    for portability reasons.
  27. //
  28. //    The code in this module should be written entirely in C. 
  29. //    Do not use any C++ constructs.
  30. //
  31. //    This module is portable to:
  32. //        DOS 3.X+
  33. //        MS Windows 3.X+
  34. //        OS/2 2.X+
  35. //        OS/2 2.0 PM
  36. //        SCO UNIX.
  37. //
  38. //    The following compilers are supported:
  39. //        MSC 6.0A
  40. //        MSC/C++ 7.0
  41. //        Borland C++ 3.1 for DOS
  42. //        Borland C++ 1.0 for OS/2 2.X
  43. //        SCO UNIX cc
  44. //
  45. //----------------------------------------------------------------------------
  46. #include <bs.h>
  47.  
  48.  
  49. //----------------------------------------------------------------------------
  50. //    Globals
  51. //----------------------------------------------------------------------------
  52. static ULONG ulCritCount = 0;
  53.  
  54.  
  55. //----------------------------------------------------------------------------
  56. //   Description:    Enter critical section code
  57. //                          Not applicatable to DOS mode, although it could be used
  58. //                        to prevent critical section conflict amoung interrupt
  59. //                        handlers.
  60. //    Parameters:
  61. //       Returns:    TRUE if successful.
  62. //----------------------------------------------------------------------------
  63. VOID FN_E CritSecEnter(void)
  64. {
  65. #if OS_OS2 || OS_PM
  66.    DosEnterCritSec();
  67. #endif
  68.     ulCritCount++;                                // Initial count
  69.     if (ulCritCount == MAX_ULONG)            // Increment count 
  70.       {
  71.         Halt("Critical section counter overflow.");
  72.         return ;
  73.         }
  74.     return ;
  75. }
  76.  
  77.  
  78. //----------------------------------------------------------------------------
  79. //   Description:    Exit critical section code
  80. //    Parameters:    None
  81. //       Returns:    void
  82. //----------------------------------------------------------------------------
  83. VOID FN_E CritSecExit(void)
  84. {
  85.     if (!ulCritCount)
  86.         {
  87.         Halt("Critical section counter underflow.");
  88.         return ;
  89.         }
  90.     ulCritCount--;                                // Decrement count
  91. #if OS_OS2 || OS_PM
  92.     DosExitCritSec();
  93. #endif
  94.     return ;
  95. }
  96. //----------------------------------------------------------------------------
  97. //------------------------------- End of File --------------------------------
  98. //----------------------------------------------------------------------------
  99.  
  100.